package cn.com.b2office.struts2.action;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import cn.com.b2office.domain.Category;
import cn.com.b2office.service.CategoryService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author zhenggang
 * @version Jul 7, 2008 9:47:27 AM
 * comment	显示所有商品分类
 */
public class AllCategoriesViewAction extends ActionSupport {
	private static final long serialVersionUID = 1L;

	private CategoryService categoryService;
	private List<List<Category>> listCategories = new ArrayList<List<Category>>();
	
	public String execute() throws Exception{
		
		Map<Category, List<Category>> tempMap = categoryService.listCascadeCategories();
		Iterator<Category> iterator = tempMap.keySet().iterator();
		while (iterator.hasNext()) {
			Category ct = iterator.next();
			List<Category> childs = (List<Category>) tempMap.get(ct);
			List list = new ArrayList();
			list.add(ct);
			list.add(childs);
			listCategories.add(list);
		}
		return SUCCESS;
		
	}

	public List getListCategories() {
		return listCategories;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

}
